package ctrl;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import chat.user.UserBean;


public class LoginActionCtrl extends HttpServlet {
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		String path = req.getContextPath();

		//接收参数

		String name = req.getParameter("name");
		String pwd = req.getParameter("pwd");
		
		
		String msg = "false~用户名必填！";
		System.out.println(msg);
		if("".equals(name)||"".equals(msg)){
			
			System.out.println(msg);
			resp.sendRedirect(path+"/page/LoginPageCtrl.php?msg="+msg);
		}else{
			
			UserBean u = new UserBean(name);
			
			req.getSession().setAttribute("userBean", u);
			req.setAttribute("path", path);
			resp.sendRedirect(path+"/page/ChatViewCtrl.php");
			/*req.getRequestDispatcher(path+"/page/ChatViewCtrl.php").forward(req, resp);*/
		}
	
	}

}
